package worker;

import java.io.IOException;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import javax.jms.JMSException;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;

import data.Data;

public class GetUrlDetail extends TimerTask{
	public void run() {
		DBCollection coll = Data.data("urlCraw");

		DBCursor lobj = coll.find(new BasicDBObject("status","true"));
		
		DBCollection collection = Data.data("logclient");
		DBObject object = collection.findOne();
		object.put("log", new Date()+"|"+lobj.count());
		collection.save(object);
		
		while (lobj.hasNext()) {
			DBObject dbObject = lobj.next();
			
			try {
				new GetUrl(dbObject);
			} catch (Exception e) {
				e.printStackTrace();
			}
			try {
				Thread.sleep(3000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	public static void main(String[] args) throws JMSException, IOException {

		Timer timer = new Timer();
		GetUrlDetail setDataWorker = new GetUrlDetail();

	    // Schedule to run after every 3 second(3000 millisecond)

	    timer.scheduleAtFixedRate( setDataWorker, 0,1000*60*10);
	}
}
